<%@ include file="/taglibs.jsp"%>
<%@ page
	import="java.util.*,
        java.util.Iterator,
        com.stable.model.TblAbteilung,
        com.stable.model.TblRolle,
        com.stable.model.TblMitarbeiter, 
        com.stable.dao.Dao"%>
<script language="JavaScript" src="md5.js"></script>
<script language="JavaScript">
            function doLogin()
            {
            
          // alert(document.forms[0].j_password.value);
           if (document.forms[0].j_password.value == '')
            {
              alert("Bitte geben Sie ihr Passwort ein"); 
              return false;
              }    


            if (document.forms[0].changed.value == '1')
            {
            document.forms[0].j_password.value = hex_md5(document.forms[0].j_password.value);
            return true;
            }

            }
        </script>

<table class="wm_hide" id="info">

	<tr>
		<td class="wm_info_message" id="info_message"></td>
	</tr>
</table>
<div align="center" id="content">
<div class="wm_logo" id="logo" tabindex="-1"></div>
<div id="login_screen">
<div class="wm_hide" id="login_error"></div>

<html:form action="mitarbeiter.do?method=MitarbeiterAktualisieren"
	onsubmit="return doLogin()">


	<table class="wm_login wm_fixed" id="login_table" border="0"
		cellspacing="0" cellpadding="0">
		<col width="100"></col>
		<col width="88"></col>
		<col width="70"></col>
		<col width="33"></col>
		<col width="42"></col>
                
    <tr>
        <br>
        <br>
        <br>
        <br>
        
        <% String mitarbeiterId = (String)request.getAttribute("mitarbeiterId");
        TblMitarbeiter mitarbeiter = (TblMitarbeiter)new Dao().get(TblMitarbeiter.class, Integer.valueOf(mitarbeiterId));%>
        <td class="wm_login_header" colspan="5">Mitarbeiter
        bearbeiten</td>
    </tr>
		<tr>
			<td class="wm_title" width="299"><bean:message key="firstName" />:</td>

			<td colspan="4"><html:text name="userForm" property="firstname"
				styleClass="wm_input" maxlength="255"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';" value="<%=mitarbeiter.getVorname()%>" /></td>
		</tr>
		<tr>
			<td class="wm_title" width="299"><bean:message key="lastName" />:</td>

			<td colspan="4"><html:text name="userForm" property="lastname"
				styleClass="wm_input" maxlength="255"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';" value="<%=mitarbeiter.getName()%>"/></td>
		</tr>

		<tr id="login_cont">
			<td class="wm_title" width="299"><bean:message key="username" />:*</td>
			<td colspan="4"><html:text name="userForm" property="loginname"
				styleClass="wm_input" maxlength="255"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';" value="<%=mitarbeiter.getLoginname()%>"/></td>
		</tr>
		<tr>
			<td class="wm_title" width="299"><bean:message key="password" />:*</td>

			<td colspan="4">
                            <html:password name="userForm" styleClass="wm_input" maxlength="255"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';" 
				property="j_password" value="<%=mitarbeiter.getPass()%>"
				onchange="changed.value='1'" /> <input type="hidden" name="changed"
				value="0" />
                                                      
                            </td>
  
		</tr>
		<tr>
			<td class="wm_title" width="299"><bean:message key="abteilung" />:</td>
			<td colspan="4">
			<%
						List alleAbteilungen = (List) request
						.getAttribute("alleAbteilungen");
				if (alleAbteilungen != null) {
			%> <select name="abtId" size="1"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';" >
				<%
						for (Iterator iterator = alleAbteilungen.iterator(); iterator
						.hasNext();) {
							TblAbteilung abt = (TblAbteilung) iterator.next();
							System.out.println(abt);
                                                        if(mitarbeiter.getAbteilungId().equals(new Integer(abt.getAbteilungId()))){
				%>
				<option value="<%=String.valueOf(abt.getAbteilungId())%>" selected="true">
					<%=abt.getName()%>
				</option>
                                <%
				}else{%>
                                <option value="<%=String.valueOf(abt.getAbteilungId())%>">
					<%=abt.getName()%>
				</option>
                                
                                <%}}
				%>
			</select> 
 <%
 }
 %>
			</td>

		</tr>
		<tr>
			<td class="wm_title" width="299"><bean:message key="rolle" />:</td>
			<td colspan="4" class="wm_input">
			<%
				List alleRollen = (List) request.getAttribute("alleRollen");
				if (alleRollen != null) {
			%> <select name="rolleId" size="1"
				onfocus="this.className = 'wm_input_focus';"
				onblur="this.className = 'wm_input';">
				<%
						for (Iterator iterator = alleRollen.iterator(); iterator
						.hasNext();) {
							TblRolle rolle = (TblRolle) iterator.next();
							System.out.println(rolle);
                                                    if (mitarbeiter.getRolleId().equals(rolle.getRolleId())){
				%>
				<option value="<%=String.valueOf(rolle.getRolleId())%>" selected="true">
					<%=rolle.getBez()%>
				</option>
 <%}else{%>
 				<option value="<%=String.valueOf(rolle.getRolleId())%>" >
					<%=rolle.getBez()%>
				</option>
 <%}
 }
 %>
			</select> 
                         <%
 }
 %>
			</td>

		</tr>
		<tr>
                    <input type="hidden" name="mitarbeiterId" value="<%=mitarbeiter.getMitarbeiterId()%>" />
			<td colspan="5"><span class="wm_login_button"> <input
				class="wm_button" type="submit"
				value='<bean:message key="link.form.save"/>' /> </span></td>
		</tr>
	</table>
</html:form></div>
</div>
